@inherits MiniRazor.TemplateBase<CodeEntity>
@namespace OSharp.CodeGeneration.Templates
@using System;
@using System.Collections.Generic
@using System.Linq
@using OSharp.CodeGeneration.Services.Entities
@using OSharp.CodeGeneration.Utils
@using OSharp.Collections;
@using OSharp.Exceptions;
@using OSharp.Extensions;
@{
    CodeEntity entity = Model;
    string keyType = TypeHelper.ToSingleTypeName(entity.PrimaryKeyTypeFullName);
}// -----------------------------------------------------------------------
// <auto-generated>
//    此代码由代码生成器生成。
//    手动更改此文件可能导致应用程序出现意外的行为。
//    如果重新生成代码，对此文件的任何修改都会丢失。
//    如果需要扩展此类：可遵守如下规则进行扩展：
//      1.横向扩展：如需添加额外的属性，可新建文件“@(entity.Name)InputDto.cs”的分部类“public partial class @(entity.Name)InputDto”添加属性
// </auto-generated>
//
// <copyright file="@(entity.Name)InputDto.generated.cs" company="@entity.Module.Project.Company">
//    @entity.Module.Project.Copyright
// </copyright>
// <site>@entity.Module.Project.SiteUrl</site>
// <last-editor>@entity.Module.Project.Creator</last-editor>
// -----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

using OSharp.Entity;
using OSharp.Mapping;

using @(entity.Module.Namespace).Entities;


namespace @(entity.Module.Namespace).Dtos
{
    /// &lt;summary&gt;
    /// 输入DTO：@(entity.Display)信息
    /// &lt;/summary&gt;
    [MapTo(typeof(@(entity.Name)))]
    [Description("@(entity.Display)信息")]
    public partial class @(entity.Name)InputDto : @(GetInterfaces(entity, keyType))
    {
        /// &lt;summary&gt;
        /// 获取或设置 编号
        /// &lt;/summary&gt;
        [DisplayName("编号")]
        public @(keyType) Id { get; set; }

@foreach (CodeProperty prop in entity.Properties.Where(m => m.IsInputDto))
{
<text>        /// &lt;summary&gt;
        /// 获取或设置 @(prop.Display)
        /// &lt;/summary&gt;
        [@GetAttributes(prop)]
        public @GetPropString(prop) @prop.Name { get; set; }

</text>
}
@if (entity.HasLocked)
{
<text>        /// <summary>
        /// 获取或设置 是否锁定
        /// </summary>
        [DisplayName("是否锁定")]
        public bool IsLocked { get; set; }

</text>
}
    }
}
@functions
{
    private static string GetInterfaces(CodeEntity entity, string keyType)
    {
      List<string> list = new List<string>();
      list.Add($"IInputDto<{keyType}>");
      list.AddIf("ILockable", entity.HasLocked);

      return list.ExpandAndToString(", ");
    }

    private static string GetAttributes(CodeProperty prop)
    {
      List<string>list = new List<string>();
      list.Add($"DisplayName(\"{prop.Display}\")");
      if (prop.TypeName == "System.String")
      {
        if (prop.IsRequired.HasValue && prop.IsRequired.Value)
        {
          list.Add("Required");
        }
        if (prop.MaxLength > 0)
        {
          string min = prop.MinLength > -1 ? $", MinimumLength = {prop.MinLength.Value}" : "";
          list.Add($"StringLength({prop.MaxLength.Value}{min})");
        }
      }
      return list.ExpandAndToString(", ");
    }

    private static string GetPropString(CodeProperty prop)
    {
      List<string>list = new List<string>();
      
      string propType = TypeHelper.ToSingleTypeName(prop.TypeName);
      //可空的值类型，添加?符号
      Type tmpType = Type.GetType(prop.TypeName);
      if (prop.IsNullable && tmpType is {IsValueType: true })
      {
        propType += "?";
      }
      list.Add(propType);

      return list.ExpandAndToString("");
    }

}
